package com.ruoyi.web.controller.check;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.check.domain.ECheckListFormItem;
import com.ruoyi.check.service.ISequenceService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.check.domain.ECheckListFormXunjian;
import com.ruoyi.check.service.IECheckListFormXunjianService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 巡检管理Controller
 *
 * @author hugh.sun
 * @date 2023-05-15
 */
@RestController
@RequestMapping("/check/xunjian")
public class ECheckListFormXunjianController extends BaseController
{
    @Autowired
    private IECheckListFormXunjianService eCheckListFormXunjianService;

    @Autowired
    private ISequenceService sequenceService;


    /**
     * 查询巡检管理列表
     */
    @PreAuthorize("@ss.hasPermi('check:xunjian:list')")
    @GetMapping("/list")
    public TableDataInfo list(ECheckListFormXunjian eCheckListFormXunjian)
    {
        startPage();
        List<ECheckListFormXunjian> list = eCheckListFormXunjianService.selectECheckListFormXunjianList(eCheckListFormXunjian);
        return getDataTable(list);
    }
    @GetMapping("/list2")
    public String list2(String name)
    {
        System.out.println(name+"------------------------------------------------");
        ECheckListFormXunjian item = new ECheckListFormXunjian();
        item.setBiaoming(name);
        Long yixunjian = 0L;
        Long dangqian =0L;
        //这个表的应该巡检的次数
        try {
            List<ECheckListFormXunjian> list = eCheckListFormXunjianService.selectECheckListFormXunjianList(item);
            ECheckListFormXunjian eCheckListFormXunjian = list.get(0);
            yixunjian = eCheckListFormXunjian.getYingxunjian();

        }catch (Exception e){
            yixunjian = 0L;

        }
        try{
            dangqian = sequenceService.xunjianduoshaoci(name);

        }catch (Exception e){
            dangqian = 0L;
        }
        Long a = dangqian+1;

        System.out.println("应该巡检:"+yixunjian+"当前是次数："+a);

        return "应该巡检:"+yixunjian+"当前是次数："+a;
    }

    @GetMapping("/list1")
    public TableDataInfo list1( )
    {
        ECheckListFormXunjian item = new ECheckListFormXunjian();

        List<ECheckListFormXunjian> list = eCheckListFormXunjianService.selectECheckListFormXunjianList(item);
        return getDataTable(list);
    }

    /**
     * 导出巡检管理列表
     */
    @PreAuthorize("@ss.hasPermi('check:xunjian:export')")
    @Log(title = "巡检管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ECheckListFormXunjian eCheckListFormXunjian)
    {
        List<ECheckListFormXunjian> list = eCheckListFormXunjianService.selectECheckListFormXunjianList(eCheckListFormXunjian);
        ExcelUtil<ECheckListFormXunjian> util = new ExcelUtil<ECheckListFormXunjian>(ECheckListFormXunjian.class);
        util.exportExcel(response, list, "巡检管理数据");
    }

    /**
     * 获取巡检管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('check:xunjian:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(eCheckListFormXunjianService.selectECheckListFormXunjianById(id));
    }

    /**
     * 新增巡检管理
     */
    @PreAuthorize("@ss.hasPermi('check:xunjian:add')")
    @Log(title = "巡检管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ECheckListFormXunjian eCheckListFormXunjian)
    {
        return toAjax(eCheckListFormXunjianService.insertECheckListFormXunjian(eCheckListFormXunjian));
    }

    /**
     * 修改巡检管理
     */
    @PreAuthorize("@ss.hasPermi('check:xunjian:edit')")
    @Log(title = "巡检管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ECheckListFormXunjian eCheckListFormXunjian)
    {
        return toAjax(eCheckListFormXunjianService.updateECheckListFormXunjian(eCheckListFormXunjian));
    }

    /**
     * 删除巡检管理
     */
    @PreAuthorize("@ss.hasPermi('check:xunjian:remove')")
    @Log(title = "巡检管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(eCheckListFormXunjianService.deleteECheckListFormXunjianByIds(ids));
    }
}
